<?php 

require_once('init.php');
require_once('./classes/flags.php');
include('inc/top.php');

$flags = $_POST['a'].$_POST['b'].$_POST['c'].$_POST['d'].$_POST['e'].$_POST['f'].$_POST['g'].$_POST['h'].$_POST['i'].$_POST['j'].$_POST['k'].$_POST['l'].$_POST['m'].$_POST['n'].$_POST['z'].$_POST['o'].$_POST['p'].$_POST['q'].$_POST['r'].$_POST['s'].$_POST['t'];

if ($user->data['group_id'] != $mgmtgroup) { echo '<div id="main_yellow"><p>You must be an administrator to view this page.</p></div>'; } else {

if (!$phpbb_groups_enabled) { echo '<div id="main_yellow"><p>phpBB groups integration is not enabled.</p></div>'; } else {

?>

<div id="main_gray"><h1>Add phpBB Group</h1></div>

<?php 

if(isset($_POST['addgroup'])) {

$input_groupid = sanitizeString($_POST['form_groupid']);
$input_flags = $flags;
$input_immunity = sanitizeString($_POST['form_immunity']);

mysql_query("INSERT INTO sm_groups_phpbb (id, flags, immunity_level) VALUES ('$input_groupid', '$input_flags', '$input_immunity')") or die(mysql_error());
echo "<a href='groups_phpbb.php'><div id='main_green'><p>Group Added Sucessfully!</p></div></a>";
} else {

$bbgroup_query_text = "SELECT sm_groups_phpbb.id, group_id, group_name FROM $phpbbdb." . GROUPS_TABLE . " LEFT JOIN sm_groups_phpbb ON " . GROUPS_TABLE . ".group_id = sm_groups_phpbb.id WHERE sm_groups_phpbb.id IS NULL;";
$bbgroup_query = mysql_query($bbgroup_query_text) or die(mysql_error());

$bbgroup_select_text = "";
while($bbgroup_result = mysql_fetch_assoc($bbgroup_query))
{
	$bbgroup_select_text .= "<option value=\"" . $bbgroup_result['group_id'] . "\">" . $bbgroup_result['group_name'] . "</option>";
}

?>

<form method="post" name="Add phpBB Group" action="addgroup_phpbb.php">

<table class="table" id="tableborder" cellspacing="0" cellpadding="5" align="center">
	<tr><td align="right"><b>Name:</b></td>
		<td align="left">
			<select name="form_groupid"> <?php echo($bbgroup_select_text); ?> </select>
		</td>
	</tr>
	<tr><td align="right"><b>Flags:</b></td><td align="left">
	
		<?php 
			for ($i = 0; $i <= 20; $i++) {
		?><input type="checkbox" name="<?php 
			echo $flag['flag'][$i];
		?>" value="<?php 
			echo $flag['flag'][$i];
		?>" />
			<?php  echo $flag['name'][$i]; ?><br/><?php  } ?>

	</td></tr>		
	<tr><td align="right"><b>Immunity:</b></td><td align="left"><input name="form_immunity" type="text" class="searchinput" /></td></tr>
	
	<tr><td colspan="2" align="center"><input name="addgroup" type="submit" value="Add Group" class="searchbutton" /></td></tr>
</table>
</form>

<?php  

}
}
}

include('inc/bottom.php'); 

?>